package com.dixon.worddayday.dao;

import com.dixon.worddayday.model.Progress;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ProgressRepository extends JpaRepository<Progress, Integer>, JpaSpecificationExecutor<Progress> {

//    @Query("select new com.dixon.worddayday.bo.ReviewWord(p.id ,w.word,w.wordShow,w.definition,w.voiceUrl) from Progress p left join Words w on p.wordId=w.id "+
//            "where p.customerId= :customerId " +
//            "order by p.createTime asc")
//    List<ReviewWord> findReviewWordsByCustomerId(@Param("customerId") Integer customerId);

    List<Progress> findByWordIdAndCustomerId(Integer wordId, Integer customerId);

    @Query("select count(distinct wordId) from Progress where customerId= :customerId")
    int countTotal(@Param("customerId") Integer customerId);

    @Query("select count(distinct wordId) from Progress where customerId= :customerId and status='2'")
    int countComplete(@Param("customerId") Integer customerId);
}
